import 'package:flutter/material.dart'; 
import '../../models/home_info_model.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';
import '../../manger/cached_image_widget.dart';

typedef PlayPushDetailCallback = void Function(int subId);

class HomeNewPlayView extends StatelessWidget {
  final PlayPushDetailCallback? onPlayPushDetail;
  final List<NewListModel> newList;
 
  const HomeNewPlayView({
    Key? key,
    this.onPlayPushDetail, 
    required this.newList, 
  }) : super(key: key);
 
  @override 
  Widget build(BuildContext context) {
    final localizations = AppLocalizations.of(context)!;

    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 15),
      decoration: BoxDecoration(
        color: Colors.white, 
        borderRadius: BorderRadius.circular(10), 
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start, 
        children: [
          Padding(
            // 修改为上边和左边 padding 为 15
            padding: const EdgeInsets.only(top: 15, left: 15), 
            child: Text(
              localizations.newProduct,
              style: TextStyle(
                color: Colors.black, 
                fontSize: 16,
                fontWeight: FontWeight.bold, 
              ),
            ),
          ),
          SizedBox(
            height: 155,
            child: ListView.builder( 
              scrollDirection: Axis.horizontal, 
              padding: const EdgeInsets.only(top: 12, left: 15), 
              itemCount: newList.length, 
              itemBuilder: (context, index) {
                final model = newList[index];
                return GestureDetector(
                  onTap: () => onPlayPushDetail?.call(model.id), 
                  child: NewPlayCell(model: model),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}

class NewPlayCell extends StatelessWidget {
  final NewListModel model;

  const NewPlayCell({Key? key, required this.model})  : super(key: key);
 
  @override 
  Widget build(BuildContext context) {
    // final localizations = AppLocalizations.of(context)!;
    // String modelName = localizations.jianzhuanfan(model.name);

    return Container(
      width: 200,
      margin: const EdgeInsets.only(right:  15,top: 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start, 
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(10), 
            child: CachedImage(
                    width: 200,  // 固定宽度为 50
                    height: 100,  // 固定高度为 50
                    imageUrl: model.cover,
                    fit: BoxFit.cover,
                    placeholderPath: 'assets/images/placeholderImage.png',  // 占位符图片路径 
            ),
          ),
          const SizedBox(height: 10),
          Text(
            model.name, 
            style: TextStyle(
              fontSize: 14,
              color: Colors.black, 
            ),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    );
  }
}